﻿using System;
using CI.Models.Production;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CI.Models.Tests
{
    [TestClass]
    public class QuantityCalculatorTests
    {
        [TestMethod]
        public void QuantityCalculatorTimespan_5MinutesX210TotalInitial()
        {
            var q = new QuantityCalculator<TimeSpan>(TimeSpan.FromMinutes(5), 2);

            Assert.AreEqual(TimeSpan.FromMinutes(10), q.Total);
        }

        [TestMethod]
        public void QuantityCalculatorTimespan_5MinutesX210ChangeRunsTo3()
        {
            var q = new QuantityCalculator<TimeSpan>(TimeSpan.FromMinutes(5), 2) {Runs = 3};

            Assert.AreEqual(TimeSpan.FromMinutes(15), q.Total);
        }

        [TestMethod]
        public void QuantityCalculator_Int_5X2_10_Total_Initial()
        {
            var q = new QuantityCalculator<int>(5, 2);

            Assert.AreEqual(10, q.Total);
        }

        [TestMethod]
        public void QuantityCalculator_Int_5X2_10_ChangeRunsTo3()
        {
            var q = new QuantityCalculator<int>(5, 2) {Runs = 3};

            Assert.AreEqual(15, q.Total);
        }

        [TestMethod]
        [ExpectedException(typeof(CannotEditException))]
        public void QuantityCalculator_IsPerRunEdittable_False_Throws_CannotEditException()
        {
            var q = new QuantityCalculator<int>(5, 2,false) { PerRun = 3 };
        }

        [TestMethod]
        public void QuantityCalculator_IsPerRunEdittable_True_Does_Not_Throw_CannotEditException()
        {
            var q = new QuantityCalculator<int>(5, 2, true) { PerRun = 3 };
        }

        [TestMethod]
        public void QuantityCalculator_Int_5X2_10_ChangePerRunsTo6()
        {
            var q = new QuantityCalculator<int>(5, 2,true) {PerRun = 6};

            Assert.AreEqual(12, q.Total);
        }

        [TestMethod]
        public void QuantityCalculator_UpdateChangeOnTotalForTimeSpan()
        {
            var q = new QuantityCalculator<TimeSpan>(TimeSpan.FromSeconds(60), 2) {Total = TimeSpan.FromSeconds(600)};

            Assert.AreEqual(10, q.Runs);
            Assert.AreEqual(TimeSpan.FromSeconds(600), q.Total);
        }

        [TestMethod]
        public void QuantityCalculator_UpdatesChangeOnTotalForInt_ExactMargin()
        {
            var q = new QuantityCalculator<int>(5, 2) {Total = 20};

            Assert.AreEqual(4, q.Runs);
        }

        [TestMethod]
        public void QuantityCalculator_UpdatesChangeOnTotalForInt_OverProduce()
        {
            var q = new QuantityCalculator<int>(5, 2) {Total = 22};

            Assert.AreEqual(5, q.Runs);
            Assert.AreEqual(25, q.Total);
        }
    }
}